<template>
  	<div class="page-content">


    <el-tabs v-model="activeName">
    <el-tab-pane label="投喂记录" name="first">
  
      <!-- 投喂记录条件筛选 -->
    	<table-bar :showTop="false"  @changeColumn="changeColumn">
      <div slot="top">
        <el-form label-width="70px" :model="params" ref="tiaojianRef" :rules="paramsRules">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="操作人：" prop="operator">
                  <el-input placeholder="操作人" v-model="params.operator"></el-input>
                </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="鸽棚：" prop="dovecoteNumber">
                <el-input placeholder="鸽棚" v-model="params.dovecoteNumber"></el-input>
              </el-form-item>
            </el-col>
            <!-- 怎么搞这个 -->
             <el-col :xs="26" :sm="12" :lg="6">
              <el-form-item label="数量：" prop="feedNumber">
                <el-input placeholder="投喂数量" v-model="params.feedNumber"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
             <el-col :xs="24" :sm="12" :lg="6">
                 <el-form-item label="开始时间" label-width="95px" prop="startTime">
                       <el-date-picker                                          
                         v-model="params.startTime"                    
                         type="datetime"
                         value-format="yyyy-MM-dd HH:mm:ss" 
                         placeholder="选择日期时间">
                        </el-date-picker>
                 </el-form-item>
             </el-col>
             <el-col :xs="24" :sm="12" :lg="6">
                  <el-form-item label="截止时间" label-width="95px" prop="endTime">
                       <el-date-picker                     
                         v-model="params.endTime"
                         type="datetime"
                         value-format="yyyy-MM-dd HH:mm:ss" 
                         placeholder="选择日期时间">
                       </el-date-picker>
                   </el-form-item>
             </el-col>
            <el-row :xs="24" :sm="12" :lg="6" style="float: right; margin-right: 10px;">
              <el-button type="primary" @click="search">搜索</el-button>
              <el-button @click="reset">重置</el-button>
            </el-row>
          </el-row>
        </el-form>
      </div>
      <div slot="bottom">
        <el-button type="primary" plain  @click="addfeeddialog=true">添加记录</el-button> 
        <el-button type="danger" plain @click="multipledelete">批量删除</el-button>  
      </div>
    	</table-bar>
    
    <!-- 操作人信息表格 -->
    <el-table size="mini" ref="multipleTable" :data="userList" tooltip-effect="dark" 
    style="width: 100%"  @selection-change="handleSelectionChange">
        	<el-table-column type="selection" width="55"></el-table-column>
      		<el-table-column type="index" ></el-table-column>
          <el-table-column label="机器编号" prop="machineNumber" />
      		<el-table-column label="鸽棚" prop="dovecoteNumber"/>
          <el-table-column label="操作人" prop="operator" />
      		<el-table-column label="开始投喂" prop="startTime" width="180px"/>
          <el-table-column label="结束投喂" prop="endTime" width="180px"/>
          <el-table-column label="饲料类型" prop="name"/>
          <el-table-column label="投喂数量" prop="number" />
          <el-table-column label="饲料规格" prop="type" />
      		<el-table-column label='操作' width='180px'>
            <template  slot-scope="scope" >
                <el-button size="mini" type="primary" icon="el-icon-edit" @click="showfeeddialog(scope.row)">编辑</el-button>
               <el-button size="mini" type="danger" icon="el-icon-delete" @click="removedoperator(scope.row.id)">删除</el-button>
            </template>
         </el-table-column>
    	</el-table>
     <!-- 分页区域 -->
	  	<el-pagination  @size-change="SizeChange" @current-change="CurrentChange" :current-page="queryinfo.pagenum"
                 :page-sizes="[5, 10, 15, 20]" :page-size="queryinfo.pagesize" layout="total, sizes, prev, pager, next, jumper"
                  :total="total">
      </el-pagination>

    </el-tab-pane>
    <el-tab-pane label="投喂机器" name="second">

      <!-- 投喂机器条件筛选 -->
    	<table-bar :showTop="false"  @changeColumn="changeColumn">
      <div slot="top">
        <el-form label-width="70px" :model="mparams" ref="tiaojianRef" :rules="paramsRules">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="启动状态：" prop="open" label-width="100px">
                  <el-input placeholder="启动状态" v-model="mparams.open"></el-input>
                </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="鸽棚：" prop="dovecoteNumber">
                <el-input placeholder="鸽棚" v-model="mparams.dovecoteNumber"></el-input>
              </el-form-item>
            </el-col>
          
            <el-row :xs="24" :sm="12" :lg="6" style="float: right; margin-right: 10px;">
              <el-button type="primary" @click="msearch">搜索</el-button>
              <el-button @click="reset">重置</el-button>
            </el-row>
          </el-row>
        </el-form>
      </div>
      <div slot="bottom">
        <el-button type="primary" plain  @click="maddfeeddialog=true">添加机器</el-button> 
        <el-button type="danger" plain @click="multiMachinedelete">批量删除</el-button>  
      </div>
    	</table-bar>

        <!--投喂机信息表格 -->
    <el-table size="mini" ref="mmultipleTable" :data="machineList" tooltip-effect="dark" 
          style="width: 100%" @selection-change="handleMachineChange">
        	<el-table-column type="selection" width="55"></el-table-column>
      		<el-table-column type="index" ></el-table-column>
      		<el-table-column label="机器编号" prop="machineNumber" />
          <el-table-column label="鸽棚" prop="dovecoteNumber"/>  
      		<el-table-column label="行走速度" prop="speed"/>     		
          <el-table-column label="运行转速" prop="rev"/>
          <el-table-column label="启动时间" prop="startTime" width="150px"/>
          <el-table-column label="停止时间" prop="stopTime" width="150px"/>
          <el-table-column label="停留时间(秒)" prop="standingTime" />
          <el-table-column label="维护周期(天)" prop="maintenancePeriod"/>
          <el-table-column label="状态">
            <template slot-scope="scope">
                <el-switch
                  v-model="scope.row.open"
                  active-color="#409eff"
                  inactive-color="#dcdfe6"
                  @change="changemachine(scope.row)">
                </el-switch>
            </template>
          </el-table-column>
      		<el-table-column label='操作' width='180px'>
            <template  slot-scope="scope" >
                <el-button size="mini" type="primary" icon="el-icon-edit" @click="machinefeeddialog(scope.row)">编辑</el-button>
               <el-button size="mini" type="danger" icon="el-icon-delete"  @click="removemachine(scope.row.id)">删除</el-button>
            </template>
         </el-table-column>
    	</el-table>
     <!-- 分页区域 -->
	  	<el-pagination  @size-change="mSizeChange" @current-change="mCurrentChange" :current-page="mqueryinfo.mpagenum"
                 :page-sizes="[5, 10, 15, 20]" :page-size="mqueryinfo.mpagesize" layout="total, sizes, prev, pager, next, jumper"
                  :total="mtotal">
      </el-pagination>

    </el-tab-pane>
    </el-tabs>
		
          <!-- 添加用户投喂对话框 -->
      <el-dialog  title="添加操作人信息"  :visible.sync="addfeeddialog"  width="50%" @close="addDialogClosed">
          <el-form :model="addInfo"  ref="addRef" :rules="operatorRules" label-width="110px">
                 <el-form-item label="机器编号:" prop="machineNumber">
                   <el-input v-model="addInfo.machineNumber" ></el-input>
                 </el-form-item>
                 <el-form-item label="鸽棚:" prop="dovecoteNumber">
                    <el-select v-model="addInfo.dovecoteNumber" placeholder="请选择">
                        <el-option
                          v-for="(item,index) in doptions"
                          :key="index"
                          :label="item"
                          :value="item">
                        </el-option>
                   </el-select>
                 </el-form-item>
                 <el-form-item label="开始时间:" >
                    <el-date-picker
                      prop="startTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="addInfo.startTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                 <el-form-item label="结束时间:" >
                    <el-date-picker
                      prop="endTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="addInfo.endTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                  <el-form-item label="操作人:" prop="operator" >
                   <el-input v-model="addInfo.operator"></el-input>
                 </el-form-item>
                  <el-form-item label="饲料类型:" prop="name">
                   <el-input v-model="addInfo.name" ></el-input>
                 </el-form-item>
                  <el-form-item label="投喂数量:" prop="number">
                   <el-input v-model="addInfo.number" ></el-input>
                 </el-form-item>
                  <el-form-item label="饲料规格:" prop="type">
                   <el-input v-model="addInfo.type" placeholder="袋/100kg"></el-input>
                 </el-form-item> 
                       
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="addfeeddialog=false">取 消</el-button>
             <el-button type="primary" @click="adduser()">确 定</el-button>
            </span>
       </el-dialog>
       <!-- 编辑操作人对话框 -->
        <el-dialog  title="编辑操作人信息"  :visible.sync="editfeeddialog"  width="50%" @close="editDialogClosed">
          <el-form :model="userInfo"  ref="editRef" :rules="operatorRules" label-width="110px">
                  <el-form-item label="机器编号:" prop="machineNumber">
                   <el-input v-model="userInfo.machineNumber" ></el-input>
                 </el-form-item>               
                 <el-form-item label="鸽棚:" prop="dovecoteNumber">
                    <el-select v-model="userInfo.dovecoteNumber" placeholder="请选择">
                        <el-option
                          v-for="(item,index) in doptions"
                          :key="index"
                          :label="item"
                          :value="item">
                        </el-option>
                      </el-select>
                 </el-form-item>
                  <el-form-item label="操作人:" prop="operator" >
                   <el-input v-model="userInfo.operator"></el-input>
                 </el-form-item>
                  <el-form-item label="开始投喂:" >
                    <el-date-picker
                      prop="startTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="userInfo.startTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                  <el-form-item label="结束投喂:" >
                    <el-date-picker
                      prop="endTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="userInfo.endTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                 <el-form-item label="饲料类型:" prop="name">
                   <el-input v-model="userInfo.name" ></el-input>
                 </el-form-item>
                  <el-form-item label="投喂数量:" prop="number">
                   <el-input v-model="userInfo.number" ></el-input>
                 </el-form-item>
                  <el-form-item label="饲料规格:" prop="type">
                   <el-input v-model="userInfo.type" ></el-input>
                 </el-form-item>
                 
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="editfeeddialog=false">取 消</el-button>
             <el-button type="primary" @click="edituser(userInfo.id)">确 定</el-button>
            </span>
       </el-dialog>

        <!-- 编辑机器参数对话框 -->
        <el-dialog  title="编辑机器参数信息"  :visible.sync="meditfeeddialog"  width="50%" @close="meditDialogClosed">
          <el-form :model="machineInfo"  ref="meditRef" :rules="machineRules" label-width="110px">
                 <el-form-item label="机器编号:" prop="machineNumber" >
                   <el-input v-model="machineInfo.machineNumber"></el-input>
                 </el-form-item>
                 <el-form-item label="鸽棚:" prop="dovecoteNumber">
                    <el-select v-model="machineInfo.dovecoteNumber" placeholder="请选择">
                        <el-option
                          v-for="(item,index) in doptions"
                          :key="index"
                          :label="item"
                          :value="item">
                        </el-option>
                   </el-select>
                 </el-form-item>
                  <el-form-item label="行走速度:" prop="speed">
                   <el-input v-model="machineInfo.speed" ></el-input>
                 </el-form-item>
                 <el-form-item label="运行转速:" prop="rev">
                   <el-input v-model="machineInfo.rev" ></el-input>
                 </el-form-item>
                  <el-form-item label="启动时间:" >
                    <el-date-picker
                      prop="startTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="machineInfo.startTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                  <el-form-item label="停止时间:" >
                    <el-date-picker
                      prop="stopTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="machineInfo.stopTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                 <el-form-item label="停留时间(秒):" prop="standingTime">
                   <el-input v-model="machineInfo.standingTime" ></el-input>
                 </el-form-item>
                  <el-form-item label="维护周期(天):" prop="maintenancePeriod">
                   <el-input v-model="machineInfo.maintenancePeriod" ></el-input>
                 </el-form-item>
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="meditfeeddialog=false">取 消</el-button>
             <el-button type="primary" @click="editmachine(machineInfo.id)">确 定</el-button>
            </span>
       </el-dialog>
         <!-- 添加机器参数对话框 -->
      <el-dialog  title="添加机器信息"  :visible.sync="maddfeeddialog"  width="50%" @close="maddDialogClosed">
          <el-form :model="maddInfo"  ref="maddRef" :rules="machineRules" label-width="110px">
                 <el-form-item label="机器编号:" prop="machineNumber" >
                   <el-input v-model="maddInfo.machineNumber"></el-input>
                 </el-form-item>
                 <el-form-item label="鸽棚:" prop="dovecoteNumber">
                  <el-select v-model="maddInfo.dovecoteNumber" placeholder="请选择">
                        <el-option
                          v-for="(item,index) in doptions"
                          :key="index"
                          :label="item"
                          :value="item">
                        </el-option>
                   </el-select>            
                 </el-form-item>
                  <el-form-item label="行走速度:" prop="speed">
                   <el-input v-model="maddInfo.speed" ></el-input>
                 </el-form-item>
                 <el-form-item label="运行转速:" prop="rev">
                   <el-input v-model="maddInfo.rev" ></el-input>
                 </el-form-item>
                  <el-form-item label="启动时间:" >
                    <el-date-picker
                      prop="startTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="maddInfo.startTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                  <el-form-item label="停止时间:" >
                    <el-date-picker
                      prop="stopTime"
                      value-format="yyyy-MM-dd HH:mm:ss" 
                      v-model="maddInfo.stopTime"                    
                      type="datetime"
                      placeholder="选择日期时间">
                     </el-date-picker>
                 </el-form-item>
                 <el-form-item label="停留时间(秒):" prop="standingTime">
                   <el-input v-model="maddInfo.standingTime" ></el-input>
                 </el-form-item>
                  <el-form-item label="维护周期(天):" prop="maintenancePeriod">
                   <el-input v-model="maddInfo.maintenancePeriod" ></el-input>
                 </el-form-item>  
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="maddfeeddialog=false">取 消</el-button>
             <el-button type="primary" @click="addmachine()">确 定</el-button>
            </span>
       </el-dialog>
        <!-- 关机操作人信息对话框 -->
      <el-dialog  title="关机操作"  :visible.sync="closefeeddialog"  width="50%" @close="closemachinedialog">
          <el-form :model="closeInfo"  ref="closeRef" :rules=" operatorRules" label-width="110px">
                 <el-form-item label="机器编号:" prop="machineNumber" >
                   <el-input v-model="closeInfo.machineNumber" disabled></el-input>
                 </el-form-item>
                 <el-form-item label="操作人:" prop="operator">
                   <el-input v-model="closeInfo.operator" ></el-input>
                 </el-form-item>
                  <el-form-item label="投喂数量(kg):" prop="number">
                   <el-input v-model="closeInfo.number" ></el-input>
                 </el-form-item>
          </el-form>
           <span slot="footer" class="dialog-footer">
             <el-button @click="closefeeddialog=false">取 消</el-button>
             <el-button type="primary" @click="closemachine()">确 定</el-button>
            </span>
       </el-dialog>
  	</div>
</template>

<script>
import {
    getAllDovecoteNumber,
    userslist,
    adduser,
    edituser,
    deleteuser,
    multipledelete,
    machinelist,
    editmachine,
    deletemachine,
    addmachine,
    multimachinedelete,
    openmachine,
    closemachine
} from "../../../api/Dovecote/InfoManage/Feed";
export default {
  	name: "Feed",

  	meta: {
  	  	title: "投喂",
  	},

	data () {
      return {
        activeName: 'first',
        dvEdit: false,
        dialogTitle: '',
        Feeddialog:false,
        form: {
          username: '',
          mibile: '',
          email: '',
          sex: 1,
          dep: '',
          status: true
        },
        options: [{
          value: '1',
          label: 'A01'
        }, {
          value: '2',
          label: 'A02'
        }],
        value: '',
        // 鸽棚多选
        doptions:[],
        baseid:0,
        userList:[],
        queryinfo :{
                // 自带参数，用于搜索
                 pagenum:1,
                 pagesize:10
            },
        total:0,
        // 搜索参数
        params:{
           dovecoteNumber:'',
           operator:'',
           feedNumber:'',
           startTime:'',
           endTime:'',
        },
         paramsRules:{
            operator:[
                   { message: '请输入操作人名字', trigger: 'blur' },
                ],
           feedNumber:[
                   {message: '请输入投喂数量', trigger: 'blur' },
                ],
           dovecoteNumber:[
                   {  message: '请输入对应鸽棚', trigger: 'blur'},
                ],  
           startTime:[
                 { message: '请输入开始时间', trigger: 'blur'},
           ],
           endTime:[
                 {  message: '请输入结束时间', trigger: 'blur'},
           ],
     },
     addfeeddialog:false,
     editfeeddialog:false,
     addInfo:{
         operator:'',
         dovecoteNumber:'',
         number:0,
         type:'',
         name:'',
         machineNumber:'',
         startTime:'',
         endTime:''
     },
     // 添加/编辑操作人格式规则
        operatorRules:{
           operator:[
                   { required: true, message: '请输入操作人名字', trigger: 'blur' },
                ],
           dovecoteNumber:[
                   {  message: '请输入鸽棚', trigger: 'blur' },
                ],
           number:[
                   { required: true, message: '请输入投喂数量', trigger: 'blur' },
                ], 
           type:[
                   { required: true, message: '请输入投喂数量单位', trigger: 'blur' },
                ],
           machineNumber:[
                   { required: true, message: '请输入机器编号', trigger: 'blur' },
                ], 
           name:[
                  { required: true, message: '请输入饲料类型', trigger: 'blur' },
                ],
           startTime:[
                   { message: '请输入开始时间', trigger: 'blur',required: true,},
                ],
          endTime:[
                   { message: '请输入结束时间', trigger: 'blur',required: true,},
                ],      
        },
        // 编辑
        userInfo:{
         operator:'',
         dovecoteNumber:'',
         number:0,
         type:'',
         name:'',
         machineNumber:'',
         startTime:'',
         endTime:''
        },
        idList:[],
        // 机器
        machineList:[],
        mqueryinfo :{
                // 自带参数，用于搜索
                 mpagenum:10,
                 mpagesize:10
            },
        mtotal:0,
        mparams:{
           dovecoteNumber:'',
           open:''
        },
        maddfeeddialog:false,
        mparamsRules:{
            dovecoteNumber:[
                   { message: '请输入鸽棚编号', trigger: 'blur' },
                ],
            open:[
                   {message: '请选择开关状态', trigger: 'blur' },
                ],
         },
         machineInfo:{
            machineNumber:'',
            dovecoteNumber:'',
            rev:'',
            speed:'',
            direction:0,
            maintenancePeriod:0,
            startTime:'',
            stopTime:'',
            standingTime:0,
            open:false,
         },
         meditfeeddialog:false,
         maddInfo:{
            machineNumber:'',
            dovecoteNumber:'',
            rev:'',
            speed:'',
            direction:0,
            maintenancePeriod:0,
            startTime:'',
            stopTime:'',
            standingTime:0,
            open:false,
         },
         machineRules:{
             machineNumber:[
                   { message: '请输入机器编号', trigger: 'blur' ,required:true},
             ],
            dovecoteNumber:[
                   { message: '请输入鸽棚编号', trigger: 'blur' },
            ],
            rev:[
                   { message: '请输入运行转速', trigger: 'blur',required:true },
            ],
            speed:[
                  { message: '请输入行走速度', trigger: 'blur',required:true },
            ],
            direction:[
                 { message: '请选择机器方向', trigger: 'blur',required:true },
            ],
            maintenancePeriod:[
                  { message: '请输入机器维护周期', trigger: 'blur' ,required:true},
            ],
            startTime:[
                 { message: '请输入机器启动时间', trigger: 'blur',required:true },
            ],
            stopTime:[
               { message: '请输入机器停止时间', trigger: 'blur',required:true },
            ],
            standingTime:[
               { message: '请输入机器停留时间', trigger: 'blur' ,required:true},
            ],
            open:[
               { message: '机器开关状态', trigger: 'blur' ,required:true},
            ],
         },
         midList:[],
          closeInfo:{
            operator:'',
            number:'',
            machineNumber:''
         },
         closefeeddialog:false
         
      };
    },
     created(){
        this.userslist();
        this.machinelist();
        this.getdovecoteNumber()
    },
    methods: {
       // 遍历对象，删除空属性值对应的属性
       filterParams(obj){
         let newPar = {};
       for (let key in obj) {
        //如果对象属性的值不为空，就保存该属性（做了限制，如果属性的值为0，保存该属性。如果属性的值全部是空格，属于为空。）
        if ((obj[key] === 0 || obj[key]) && obj[key].toString().replace(/(^\s*)|(\s*$)/g, '') !== '') {
            //记录属性
            newPar[key] = obj[key];
          }
       }
        //返回对象
        return newPar;
    },
    // 根据id选择对应的鸽棚
     async getdovecoteNumber(){
        this.baseid=this.$store.state.Usersetting.BaseInfo.id       
        const{data:res}= await getAllDovecoteNumber(this.baseid);
        if(res.statusCode!==20000){
          return this.$message.error("获取鸽棚列表失败")
        }
        this.doptions=res.data;      
      },
      // 获取操作人信息
      async userslist(){
          this.params=this.filterParams(this.params);
         const {data:res}=await userslist(this.queryinfo.pagenum,this.queryinfo.pagesize,this.params);
            if(res.statusCode!==20000){
             return this.$message.error('获取操作人信息失败')
         }else{
            this.userList=res.data.records;
            this.total=res.data.total;        
         }
        // 要添加提前验证消息
      // 编辑接口
      },
      // 监听一页有多少条数据
        SizeChange(newsize){
           this.queryinfo.pagesize=newsize;
           this.userslist();
        },
        // 监听第几页
        CurrentChange(newcurrent){
           this.queryinfo.pagenum=newcurrent;
           this.userslist();
        },
        // 添加用户
        adduser(){
         this.$refs.addRef.validate(async valid=>{
             if(!valid) return
              adduser(this.addInfo).then(res=>{
             this.userslist();            
           }).catch(error=>{             
             this.$message.error('添加操作人信息失败')
           })
           this.$refs.addRef.resetFields();
          this.addfeeddialog=false
         })
      },
        editDialogClosed(){
          this.$refs.editRef.resetFields();
       },
        meditDialogClosed(){
          this.$refs.meditRef.resetFields();
       },
        addDialogClosed(){
          this.$refs.addRef.resetFields();
       },
        maddDialogClosed(){
          this.$refs.maddRef.resetFeilds();
       },
       closemachinedialog(){
         this.$refs.closeRef.resetFields();
         this.machinelist();

       },
      // 搜索信息
      async search(){       
        this.params=this.filterParams(this.params);
        const {data:res}=await userslist(this.queryinfo.pagenum,this.queryinfo.pagesize,this.params);          
            if(res.statusCode!==20000){
             return this.$message.error('所查询用户信息不存在！')
         }else{
            this.userList=res.data.records;
         };
      },
      // 重置
      reset(){          
           this.$refs.tiaojianRef.resetFields();
      },
      // 把这一行的操作人信息赋值给userInfo
       showfeeddialog(item){
          this.editfeeddialog=true
          this.userInfo = item
       },
      // 编辑操作人信息
      edituser(id){
        this.$refs.editRef.validate(async valid=>{
          if(!valid) return 
            this.userInfo.baseId = +this.userInfo.baseId
        delete this.userInfo.id
          const {data:res}=await edituser(id,this.userInfo);         
          this.userslist();
          this.editfeeddialog=false;
        })       
      },
      // 删除用户信息
       async removedoperator(id){
           const confirmResult=await this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning' }).catch(err=>err)

          if(confirmResult!=='confirm'){
             return this.$message.info('已取消删除操作')
          }
            deleteuser(id).then(
              res => {                            
                 this.userslist()
              }
            ).catch(error=>{
               return this.$message.error('删除操作人信息失败哦')
            })
      },
       // 监听批量删除
      handleSelectionChange(val){
           val.forEach(element => {
             this.idList.push(element.id);
           });
      },
      // 批量删除
      async multipledelete(){
           const confirmResult=await this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning' }).catch(err=>err)

          if(confirmResult!=='confirm'){
             return this.$message.info('已取消删除操作')
          }
            const {data:res}=await multipledelete(this.idList);
             if(res.statusCode!==20000){
                  return this.$message.error('获取操作人信息失败')
             }           
             this.userslist()
            this.idList=[];
      },
      changeColumn(columns) {
        this.columns = columns
        this.$refs.table.doLayout()
      },
      // 获取投喂机器信息
      async machinelist(){
          this.mparams=this.filterParams(this.mparams);
         const {data:res}=await machinelist(this.mqueryinfo.mpagenum,this.mqueryinfo.mpagesize,this.mparams);          
            if(res.statusCode!==20000){
             return this.$message.error('获取投喂机器信息失败')
         }else{
            this.machineList=res.data.records;    
            this.mtotal=res.data.total;           
         }
        // 要添加提前验证消息
      // 编辑接口
      },
      // 监听一页有多少条数据
        mSizeChange(newsize){
           this.mqueryinfo.mpagesize=newsize;
           this.machinelist();
        },
        // 监听第几页
        mCurrentChange(newcurrent){
           this.mueryinfo.mpagenum=newcurrent;
           this.machinelist();
        },
        // 搜索信息
      async msearch(){    
        this.mparams=this.filterParams(this.mparams);
        const {data:res}=await userslist(this.mqueryinfo.mpagenum,this.mqueryinfo.mpagesize,this.mparams);         
            if(res.statusCode!==20000){
             return this.$message.error('所查询用户信息不存在！')
         }else{
            this.machineList=res.data.records;
         };
      },
      // 编辑把这一行的操作人信息赋值给machineInfo
      machinefeeddialog(item){
          this.meditfeeddialog=true
          this.machineInfo=item
      },
      // 机器编辑
       editmachine(mid){
          this.$refs.meditRef.validate(async valid=>{
          if(!valid) return 
          this.machineInfo.baseId = +this.machineInfo.baseId
          delete this.machineInfo.id;
          delete this.machineInfo.name;
          delete this.machineInfo.number;
          delete this.machineInfo.type;         
          const {data:res}=await editmachine(mid,this.machineInfo);   
          this.machinelist();
          this.meditfeeddialog=false;
        })
          
      },
      // 机器根据id删除
      async removemachine(id){
           const confirmResult=await this.$confirm('此操作将永久删除该机器信息, 是否继续?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning' }).catch(err=>err)

          if(confirmResult!=='confirm'){
             return this.$message.info('已取消删除操作')
          }
             deletemachine(id).then(
              res => {                       
                 this.machinelist();
              }
            ).catch(error=>{
               return this.$message.error('删除机器信息失败')
            })
      },
      // 添加机器
      addmachine(){
         this.$refs.maddRef.validate(async valid=>{
            if(!valid) return
            addmachine(this.maddInfo).then(res=>{
             this.machinelist();
             this.$message.error('添加机器信息成功')
           }).catch(error=>{           
             this.$message.error('添加机器信息失败')
           })
           this.$refs.maddRef.resetFields();
          this.maddfeeddialog=false
        })        
      },
        // 监听机器批量删除
      handleMachineChange(val){
           val.forEach(element => {
             this.midList.push(element.id);
           });
      },
      // 机器的批量删除
      async multiMachinedelete(){
           const confirmResult=await this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning' }).catch(err=>err)

          if(confirmResult!=='confirm'){
             return this.$message.info('已取消删除操作')
          }
            const {data:res}=await multimachinedelete(this.midList);
             if(res.statusCode!==20000){
                  return this.$message.error('批量删除机器信息失败')
             }           
            this.machinelist();
            this.midList=[];
      },
      // 监听机器开关状态
       async changemachine(item){
          if(item.open){          
            const{data:res}=await openmachine(item.machineNumber);
            if(res.statusCode!==20000){
              return this.$message.error('机器启动失败')
            }
          }else{                
            this.closeInfo.machineNumber=item.machineNumber;
            this.closefeeddialog=true;           
          }
        },
        // 关机器
        async closemachine(){
           const{data:res}=await closemachine(this.closeInfo);
           if(res.statusCode!==20000){
              return this.$message.error('机器关机失败')
            }
          else{   
            this.closefeeddialog=false;
            this.$refs.closeRef.resetFields();          
          }
        },
    }
  }
</script>
<style scoped>
.el-table td, .el-table th {
    text-align: center;
} 
/* 时间宽度 */
.el-date-editor.el-input, .el-date-editor.el-input__inner {
      width: 100%;
    }
    /* 下拉框宽度 */
.el-select, .el-select--small{
  width: 100%;
}
</style>
<style lang='scss' scoped>
  .page-content {
    width: 100%;
    height: 100%;

    .avatar {
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }
    .page {
        margin-top: 6px;
        text-align: center;
    }
    
    
  }
</style>